package cn.jxwazx.sheinspringboot.entity;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;

import java.util.List;

/**
 * @author LoveHuahua
 * @date 2021年09月07日 14:39
 * @description believe in yourself
 */
@Data
public class R<T> {

    private int code;

    private String message;

    private T data;
    /**
     *
     */
    private Long total;

    public static <T> R<T> success() {
        return success(null);
    }
    public static <T> R<T> success(T t) {
        R<T> objectR = new R<>();
        objectR.setMessage("操作成功");
        objectR.setCode(200);
        objectR.setData(t);
        return objectR;
    }

    public static <T> R<List<T>> successPage(Page<T> t) {
        R<List<T>> objectR = new R<>();
        objectR.setMessage("操作成功");
        objectR.setCode(200);
        objectR.setData(t.getRecords());
        objectR.setTotal(t.getTotal());
        return objectR;
    }

    public static  R<String> error(String message) {
        return error(-1,message);
    }


    public static  R<String> error(int code,String message) {
        R<String> objectR = new R<>();
        objectR.setMessage(message);
        objectR.setCode(code);
        objectR.setData(null);
        return objectR;
    }


}
